<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="js,正则表达式," />





  <link rel="alternate" href="/atom.xml" title="OBKoro1's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="前言在我们做用户授权登录(微信,qq授权)，以及根据对应浏览器做对应的操作的时候，经常会遇到需要判断用户使用的浏览器的需求，以及在需要用户输入信息的时候，有需要验证的一些正则。如果喜欢的话可以点波赞/关注，支持一下，希望大家看完本文可以有所收获。">
<meta name="keywords" content="js,正则表达式">
<meta property="og:type" content="article">
<meta property="og:title" content="如何判断用户浏览器以及一些前端常用的正则表单验证">
<meta property="og:url" content="http://yoursite.com/2018/05/05/如何判断用户浏览器以及一些前端常用的正则表单验证/index.html">
<meta property="og:site_name" content="OBKoro1&#39;s Blog">
<meta property="og:description" content="前言在我们做用户授权登录(微信,qq授权)，以及根据对应浏览器做对应的操作的时候，经常会遇到需要判断用户使用的浏览器的需求，以及在需要用户输入信息的时候，有需要验证的一些正则。如果喜欢的话可以点波赞/关注，支持一下，希望大家看完本文可以有所收获。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1633015e7ccdb307?w=225&h=225&f=jpeg&s=7834?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1631b6f52f7e7015.jpeg?raw=true">
<meta property="og:updated_time" content="2019-07-20T06:55:39.062Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="如何判断用户浏览器以及一些前端常用的正则表单验证">
<meta name="twitter:description" content="前言在我们做用户授权登录(微信,qq授权)，以及根据对应浏览器做对应的操作的时候，经常会遇到需要判断用户使用的浏览器的需求，以及在需要用户输入信息的时候，有需要验证的一些正则。如果喜欢的话可以点波赞/关注，支持一下，希望大家看完本文可以有所收获。">
<meta name="twitter:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1633015e7ccdb307?w=225&h=225&f=jpeg&s=7834?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/05/05/如何判断用户浏览器以及一些前端常用的正则表单验证/"/>





  <title>如何判断用户浏览器以及一些前端常用的正则表单验证 | OBKoro1's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64d57d0b926bbd27431daa89d2e0a76b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">OBKoro1's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-前端算法">
          <a href="/arithmetic/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            前端算法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-博客最新更新">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            博客最新更新
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/05/05/如何判断用户浏览器以及一些前端常用的正则表单验证/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OBKoro1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/hand1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="OBKoro1's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">如何判断用户浏览器以及一些前端常用的正则表单验证</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-05-05T21:14:02+08:00">
                2018-05-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/js/" itemprop="url" rel="index">
                    <span itemprop="name">js</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2018/05/05/如何判断用户浏览器以及一些前端常用的正则表单验证/" class="leancloud_visitors" data-flag-title="如何判断用户浏览器以及一些前端常用的正则表单验证">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1,793 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  7分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1633015e7ccdb307?w=225&amp;h=225&amp;f=jpeg&amp;s=7834?raw=true" alt=""></p>
<h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p>在我们做用户授权登录(微信,qq授权)，以及根据对应浏览器做对应的操作的时候，经常会遇到需要判断用户使用的浏览器的需求，以及在需要用户输入信息的时候，有需要验证的一些正则。如果喜欢的话可以点波赞/关注，支持一下，希望大家看完本文可以有所收获。</p>
<a id="more"></a>
<blockquote>
<p>个人博客了解一下：<a href="http://obkoro1.com/" target="_blank" rel="noopener">obkoro1.com</a></p>
</blockquote>
<hr>
<h2 id="判断用户浏览器"><a href="#判断用户浏览器" class="headerlink" title="判断用户浏览器"></a>判断用户浏览器</h2><h3 id="navigator-userAgent"><a href="#navigator-userAgent" class="headerlink" title="navigator.userAgent"></a>navigator.userAgent</h3><p>判断用户所使用的浏览器主要用到的api是<a href="http://www.w3school.com.cn/htmldom/prop_nav_useragent.asp" target="_blank" rel="noopener">navigator.userAgent</a>，这是一个只读的字符串，声明了浏览器用于 HTTP 请求的用户代理头的值，不同浏览器的<code>userAgent</code>值都不相同，所以我们可以根据这个字符串来判断用户是从哪个浏览器进入的。</p>
<h3 id="判断方式："><a href="#判断方式：" class="headerlink" title="判断方式："></a>判断方式：</h3><p>下面两个是刚做的demo获取的值，仔细观察下面两个字符串，会发现有些值是不一样的，并且浏览器特有的，依据这个我们就可以作为不同浏览器的判断条件。</p>
<h4 id="QQ内置浏览器的userAgent值："><a href="#QQ内置浏览器的userAgent值：" class="headerlink" title="QQ内置浏览器的userAgent值："></a>QQ内置浏览器的userAgent值：</h4><p>mozilla/5.0 (iphone; cpu iphone os 11_1_2 like mac os x) applewebkit/604.3.5 (khtml, like gecko) mobile/15b202 qq/7.5.8.422 v1_iph_sq_7.5.8_1_app_a pixel/1080 core/uiwebview device/apple(iphone 8plus) nettype/wifi qbwebviewtype/1</p>
<h4 id="微信内置浏览器的userAgent值："><a href="#微信内置浏览器的userAgent值：" class="headerlink" title="微信内置浏览器的userAgent值："></a>微信内置浏览器的userAgent值：</h4><p>mozilla/5.0 (iphone; cpu iphone os 11_1_2 like mac os x) applewebkit/604.3.5 (khtml, like gecko) mobile/15b202 micromessenger/6.6.6 nettype/wifi language/zh_cn</p>
<h3 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h3><p>使用方式，直接使用这个api读取值，然后根据事先观察<code>userAgent</code>字符串的不同之处来判断：</p>
<pre><code>let url = navigator.userAgent.toLowerCase();
//使用toLowerCase将字符串全部转为小写 方便我们判断使用
if (url.indexOf(&quot;15b202 qq&quot;) &gt; -1) {
  //单独判断QQ内置浏览器 
  alert(&quot;QQ APP 内置浏览器，做你想做的操作&quot;);
}
if (url.indexOf(&quot;micromessenger&quot;) &gt; -1) {
  //单独判断微信内置浏览器
  alert(&apos;微信内置浏览器，做你想做的操作&apos;);
}
if (url.indexOf(&quot;15b202&quot;) &gt; -1) {
  //判断微信内置浏览器，QQ内置浏览器
  alert(&quot;QQ和微信内置浏览器，做你想做的操作&quot;);
}
</code></pre><p>上面判断了微信和QQ的内置浏览器，如果有更多不同的需求的话，可以按照上面的方式，先获取<code>userAgent</code>的字符串，然后再根据观察，使用<code>indexOf</code>判断是否含有指定的字符，来对不同浏览器进行不同的操作。</p>
<hr>
<h3 id="一部分正则判断用户输入信息"><a href="#一部分正则判断用户输入信息" class="headerlink" title="一部分正则判断用户输入信息"></a>一部分正则判断用户输入信息</h3><p>为了避免用户胡乱输入就通过验证，很多时候我们都会采用正则表达式来验证一下用户输入的信息是否符合规范。这部分的内容基本上是在网上收集来的，这里跟大家一起分享一下，有需要的可以记在自己的有道云里面。</p>
<h4 id="如何验证？"><a href="#如何验证？" class="headerlink" title="如何验证？"></a>如何验证？</h4><p>验证的方式当然是很多了，这里推荐采用<a href="http://www.w3school.com.cn/js/jsref_test_regexp.asp" target="_blank" rel="noopener">test()</a>方法来验证。</p>
<pre><code>let isTrue=RegExpObject.test(string);// RegExpObject为正则 string是要检测的字符串
// 如果字符串 string 中含有与 RegExpObject 匹配的文本，则返回 true，否则返回 false。
if (isTrue){
    //验证成功 do something
}elseP{
    //验证失败
}
</code></pre><h4 id="身份证号码正则表达式："><a href="#身份证号码正则表达式：" class="headerlink" title="身份证号码正则表达式："></a>身份证号码正则表达式：</h4><p> 第一代身份证只有15位数，第二代身份证有18位数，各位按照需求来选择表达式。</p>
<pre><code>//第二代身份证号码正则
let isTrue = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
//第一代身份证正则表达式(15位)
let isTrue=/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
</code></pre><h4 id="手机号码正则表达式："><a href="#手机号码正则表达式：" class="headerlink" title="手机号码正则表达式："></a>手机号码正则表达式：</h4><p>时间截止为：2018年1月11日</p>
<p>移动号段：134 135 136 137 138 139 147 148 150 151 152 157 158 159 172 178 182 183 184 187 188 198 </p>
<p>联通号段：130 131 132 145 146 155 156 166 171 175 176 185 186 </p>
<p>电信号段：133 149 153 173 174 177 180 181 189 199</p>
<p>虚拟运营商：170</p>
<pre><code>let isTrue = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[8-9])[0-9]{8}$/;  
</code></pre><h4 id="邮箱正则表达式："><a href="#邮箱正则表达式：" class="headerlink" title="邮箱正则表达式："></a>邮箱正则表达式：</h4><pre><code>let isTrue =/^([A-Za-z0-9_\-\.\u4e00-\u9fa5])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/;
</code></pre><h3 id="用户名正则"><a href="#用户名正则" class="headerlink" title="用户名正则:"></a>用户名正则:</h3><pre><code>////用户名正则，4到16位（字母，数字，下划线，减号）
let isTrue = /^[a-zA-Z0-9_-]{4,16}$/;
</code></pre><h4 id="密码正则"><a href="#密码正则" class="headerlink" title="密码正则:"></a>密码正则:</h4><p>密码正则，以字母开头，长度在6~18之间，只能包含字母、数字和下划线</p>
<pre><code>let isTrue =^[a-zA-Z]\w{5,17}$;
</code></pre><p>强密码正则，最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符</p>
<pre><code>let isTrue = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&amp;*? ]).*$/;
</code></pre><h4 id="QQ号码正则"><a href="#QQ号码正则" class="headerlink" title="QQ号码正则:"></a>QQ号码正则:</h4><pre><code>let isTrue = /^[1-9][0-9]{4,10}$/;
</code></pre><h4 id="微信号码正则"><a href="#微信号码正则" class="headerlink" title="微信号码正则:"></a>微信号码正则:</h4><pre><code>//微信号正则，6至20位，以字母开头，字母，数字，减号，下划线
let isTrue = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
</code></pre><h4 id="特殊字符检测正则"><a href="#特殊字符检测正则" class="headerlink" title="特殊字符检测正则:"></a>特殊字符检测正则:</h4><pre><code>let isTrue= /[&quot;&apos;&lt;&gt;%;)(&amp;+]+-!！@#$~/;
</code></pre><h4 id="域名正则"><a href="#域名正则" class="headerlink" title="域名正则:"></a>域名正则:</h4><pre><code>let isTrue=[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?;    
</code></pre><h4 id="车牌号码正则"><a href="#车牌号码正则" class="headerlink" title="车牌号码正则:"></a>车牌号码正则:</h4><pre><code>let isTrue = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
</code></pre><h4 id="包含中文正则"><a href="#包含中文正则" class="headerlink" title="包含中文正则:"></a>包含中文正则:</h4><pre><code>let isTrue = /[\u4E00-\u9FA5]/;
//这个可以用于验证用户的真实姓名。
</code></pre><h4 id="护照正则"><a href="#护照正则" class="headerlink" title="护照正则:"></a>护照正则:</h4><pre><code>let isTrue=/^(P\d{7}|G\d{7,8}|TH\d{7,8}|S\d{7,8}|A\d{7,8}|L\d{7,8}|\d{9}|D\d+|1[4,5]\d{7})$/;
</code></pre><h4 id="固定电话正则："><a href="#固定电话正则：" class="headerlink" title="固定电话正则："></a>固定电话正则：</h4><pre><code>let isTrue=(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8};
</code></pre><h4 id="IP地址正则"><a href="#IP地址正则" class="headerlink" title="IP地址正则:"></a>IP地址正则:</h4><pre><code>let isTrue=\d+\.\d+\.\d+\.\d+;
</code></pre><h4 id="邮政编码正则"><a href="#邮政编码正则" class="headerlink" title="邮政编码正则:"></a>邮政编码正则:</h4><pre><code>let isTrue=[1-9]{1}(\d+){5};
</code></pre><h4 id="经纬度正则"><a href="#经纬度正则" class="headerlink" title="经纬度正则"></a>经纬度正则</h4><pre><code>//经度正则
 let isTrue=/^(\-|\+)?(((\d|[1-9]\d|1[0-7]\d|0{1,3})\.\d{0,6})|(\d|[1-9]\d|1[0-7]\d|0{1,3})|180\.0{0,6}|180)$/;
 //纬度正则
 let isTrue=/^(\-|\+)?([0-8]?\d{1}\.\d{0,6}|90\.0{0,6}|[0-8]?\d{1}|90)$/;
</code></pre><p>常用的正则表达式大概就是上面这些了，如果大家还有其他干货的话，欢迎在评论区留言分享一下。</p>
<hr>
<h2 id="结语"><a href="#结语" class="headerlink" title="结语"></a>结语</h2><p>以上就是本文的内容了，希望大家看完可以有所收获，喜欢的话，赶紧点波<del>订阅</del>关注/喜欢，以后方便<del>查找</del>复制粘贴，233。</p>
<h3 id="希望看完的朋友可以点个喜欢-关注，您的支持是对我最大的鼓励。"><a href="#希望看完的朋友可以点个喜欢-关注，您的支持是对我最大的鼓励。" class="headerlink" title="希望看完的朋友可以点个喜欢/关注，您的支持是对我最大的鼓励。"></a>希望看完的朋友可以点个喜欢/关注，您的支持是对我最大的鼓励。</h3><p><strong>最后</strong>：如需转载，请放上原文链接并署名。码字不易，<strong>感谢</strong>支持！本人写文章本着交流记录的心态，写的不好之处，不撕逼，但是欢迎指点。</p>
<p><strong><a href="http://obkoro1.com/" target="_blank" rel="noopener">个人blog</a></strong> and <strong><a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" rel="noopener">掘金个人主页</a></strong>  </p>
<p>如果喜欢本文的话，可以关注一下我刚开的订阅号，共同学习成长。</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1631b6f52f7e7015.jpeg?raw=true" alt=""></p>
<p> 以上2018.5.5</p>
<h3 id="参考资料："><a href="#参考资料：" class="headerlink" title="参考资料："></a>参考资料：</h3><p><a href="http://www.w3school.com.cn/htmldom/prop_nav_useragent.asp" target="_blank" rel="noopener">HTML DOM userAgent 属性</a></p>
<p><a href="http://www.w3school.com.cn/js/jsref_test_regexp.asp" target="_blank" rel="noopener">JavaScript test() 方法</a></p>
<p><a href="https://blog.csdn.net/huangxiaoguo1/article/details/79785476" target="_blank" rel="noopener">2018最新手机号码正则表达式</a></p>
<p><a href="https://juejin.im/post/5aa8d89af265da23866f9669" target="_blank" rel="noopener">身份证号码的正则表达式</a></p>
<p><a href="http://www.luoxiao123.cn/mobile_phone_vaild.html" target="_blank" rel="noopener">JavaScript手机号码格式验证方法</a></p>
<p><a href="http://www.html-js.com/article/4602" target="_blank" rel="noopener">邮箱/邮件地址的正则表达式及分析</a></p>
<p><a href="http://caibaojian.com/form-regexp.html" target="_blank" rel="noopener">前端表单验证常用的15个JS正则表达式</a></p>
<p><a href="http://www.css88.com/archives/7991" target="_blank" rel="noopener">前端开发中的 正则表达式 及常用正则表达式大全</a></p>
<p><a href="https://juejin.im/post/5aa23ee46fb9a028b86d9cf4" target="_blank" rel="noopener">密码强度的正则表达式</a></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>听说，打赏我的人最后都找到了真爱。</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/weixin.jpg" alt="OBKoro1 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/ali.jpg" alt="OBKoro1 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/js/" rel="tag"><i class="fa fa-tag"></i> js</a>
          
            <a href="/tags/正则表达式/" rel="tag"><i class="fa fa-tag"></i> 正则表达式</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/04/30/前端将数据转化为弹幕效果的实现方式/" rel="next" title="前端将数据转化为弹幕效果的实现方式">
                <i class="fa fa-chevron-left"></i> 前端将数据转化为弹幕效果的实现方式
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/05/12/关于input的一些问题解决方法分享/" rel="prev" title="关于input的一些问题解决方法分享">
                关于input的一些问题解决方法分享 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/hand1.jpg"
              alt="OBKoro1" />
          
            <p class="site-author-name" itemprop="name">OBKoro1</p>
            <p class="site-description motion-element" itemprop="description">种一棵树最好的时间是十年前,其次是现在</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives">
            
                <span class="site-state-item-count">105</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/OBKoro1" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" title="掘金">
                  
                    <i class="fa fa-fw fa-globe"></i>掘金</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://obkoro1.com/web_accumulate/" target="_blank" title="前端积累">
                  
                    <i class="fa fa-fw fa-globe"></i>前端积累</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/obkoro1/articles" target="_blank" title="segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>segmentfault</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#判断用户浏览器"><span class="nav-number">2.</span> <span class="nav-text">判断用户浏览器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#navigator-userAgent"><span class="nav-number">2.1.</span> <span class="nav-text">navigator.userAgent</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#判断方式："><span class="nav-number">2.2.</span> <span class="nav-text">判断方式：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#QQ内置浏览器的userAgent值："><span class="nav-number">2.2.1.</span> <span class="nav-text">QQ内置浏览器的userAgent值：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#微信内置浏览器的userAgent值："><span class="nav-number">2.2.2.</span> <span class="nav-text">微信内置浏览器的userAgent值：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#示例"><span class="nav-number">2.3.</span> <span class="nav-text">示例</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#一部分正则判断用户输入信息"><span class="nav-number">2.4.</span> <span class="nav-text">一部分正则判断用户输入信息</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#如何验证？"><span class="nav-number">2.4.1.</span> <span class="nav-text">如何验证？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#身份证号码正则表达式："><span class="nav-number">2.4.2.</span> <span class="nav-text">身份证号码正则表达式：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#手机号码正则表达式："><span class="nav-number">2.4.3.</span> <span class="nav-text">手机号码正则表达式：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#邮箱正则表达式："><span class="nav-number">2.4.4.</span> <span class="nav-text">邮箱正则表达式：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#用户名正则"><span class="nav-number">2.5.</span> <span class="nav-text">用户名正则:</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#密码正则"><span class="nav-number">2.5.1.</span> <span class="nav-text">密码正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#QQ号码正则"><span class="nav-number">2.5.2.</span> <span class="nav-text">QQ号码正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#微信号码正则"><span class="nav-number">2.5.3.</span> <span class="nav-text">微信号码正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#特殊字符检测正则"><span class="nav-number">2.5.4.</span> <span class="nav-text">特殊字符检测正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#域名正则"><span class="nav-number">2.5.5.</span> <span class="nav-text">域名正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#车牌号码正则"><span class="nav-number">2.5.6.</span> <span class="nav-text">车牌号码正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#包含中文正则"><span class="nav-number">2.5.7.</span> <span class="nav-text">包含中文正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#护照正则"><span class="nav-number">2.5.8.</span> <span class="nav-text">护照正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#固定电话正则："><span class="nav-number">2.5.9.</span> <span class="nav-text">固定电话正则：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#IP地址正则"><span class="nav-number">2.5.10.</span> <span class="nav-text">IP地址正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#邮政编码正则"><span class="nav-number">2.5.11.</span> <span class="nav-text">邮政编码正则:</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#经纬度正则"><span class="nav-number">2.5.12.</span> <span class="nav-text">经纬度正则</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#结语"><span class="nav-number">3.</span> <span class="nav-text">结语</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#希望看完的朋友可以点个喜欢-关注，您的支持是对我最大的鼓励。"><span class="nav-number">3.1.</span> <span class="nav-text">希望看完的朋友可以点个喜欢/关注，您的支持是对我最大的鼓励。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#参考资料："><span class="nav-number">3.2.</span> <span class="nav-text">参考资料：</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OBKoro1</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">
      156.0k
    </span>
  
</div>




<div>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="site-uv"><i class="fa fa-user"></i> 访问用户： <span class="busuanzi-value" id="busuanzi_value_site_uv">21621</span> 人 </span>
<span class="site-pv"><i class="fa fa-eye"></i> 访问次数： <span class="busuanzi-value" id="busuanzi_value_site_pv">68503</span> 次</span>

</div>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("9ANFp60h6oVyxIPGlau3NOA4-gzGzoHsz", "tMdNuKMbFtN4QsekeNVu83TV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>

